/* -----------------------------------------------------------------------------
 * PROJECT    : net.lwf
 * FILE       : fVowelFamilyHandler.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * Jan 13, 2009  Raghu Sarraff			       Created
 */
package lwf.handler.english.word;

import java.util.List;
import java.util.Map;

import lwf.factory.PropertyReader;
import lwf.factory.VowelFamilyFactory;

public class VowelFamilyHandler {
	
	public static String getDisplayData(String vowel, String type) {
		
		Map mapVowelFamilies = VowelFamilyFactory.getInstance().getVowelFamilies();
		if(!mapVowelFamilies.containsKey(vowel + type)) {
			return "Sorry No data is available...........";
		}
		List vowelfamily = (List) mapVowelFamilies.get(vowel + type);
		
		StringBuffer sbdispdata = new StringBuffer();
		sbdispdata.append("<fieldset><legend>Click any of the following</legend>");
		sbdispdata.append("<table align=\"center\" width=\"90%\" border=\"0\" >");
		boolean countdisplay = false;
		int nCounter = 0;
		int nDataCount = 0;
        while(!countdisplay) {
        	sbdispdata.append("<tr>");
	        	for(int i=0; i<10; i++) {
	        		String value = "";	
	        		sbdispdata.append("<td class=\"data\" width=\"6%\">");
	        		    String vfChild = "&nbsp;";
	        			if(nDataCount<vowelfamily.size() && !countdisplay ) {
	        				vfChild = (String) vowelfamily.get(nDataCount);
	        				List lstRwords = (List)PropertyReader.getInstance().getRhymingWords().get(vfChild);
	        				if(lstRwords != null && lstRwords.size() != 0) {
		        				String onclick = "displayData('" + vfChild + "')";
		        		    	sbdispdata.append("<a href=\"#\" onclick=\"" + onclick + "\" >");
		        		    	sbdispdata.append(vfChild);
		        		    	sbdispdata.append("</a>");	        					
	        				}
	        				else {
	        					sbdispdata.append(vfChild);
	        				}
							nDataCount++;
	        		    }
	        		    else {
	        		    	sbdispdata.append("&nbsp;");
	        		    	countdisplay = true;
	        		    }
	        		sbdispdata.append("</td>");
	        		sbdispdata.append("<td width=\"3%\" >");
	        			sbdispdata.append("&nbsp;");
	        		sbdispdata.append("</td>");
	        	}
	        	nCounter = nCounter + 10;
        	sbdispdata.append("</tr>");
        }
		sbdispdata.append("</table>");			
		sbdispdata.append("</fieldset>");
		return sbdispdata.toString();
	}

} //VowelFamilyHandler

